#include <co/localNode.h>

#include "channel.h"

eqClient::Channel::Channel(eq::Window* parent): eq::Channel(parent)
{
}

bool eqClient::Channel::configInit(const eq::uint128_t& initID)
{
    return
    eq::Channel::configInit(initID) &&
    this->getLocalNode()->mapObject(&state, initID);
}

bool eqClient::Channel::configExit()
{
    this->getLocalNode()->unmapObject(&state);
    return eq::Channel::configExit();
}

void eqClient::Channel::frameDraw(const eq::uint128_t& frameID)
{
    eq::Channel::frameDraw(frameID);
    
    state.sync(frameID);
    
    eq::Range const& range = this->getRange();
    
    glTranslatef(state.position.x, state.position.y, state.position.z);
    glRotatef(state.rotate.y, 0, 1, 0);
    glRotatef(state.rotate.x, 1, 0, 0);
    glScalef(state.scale, state.scale, state.scale);
    if(0.0f >= range.start && 0.0f < range.end)
    {
        glColor3f(1, 1, 1);
        glBegin(GL_QUADS);
            glVertex2d(-1.0, -1.0);
            glVertex2d( 1.0, -1.0);
            glVertex2d( 1.0,  1.0);
            glVertex2d(-1.0,  1.0);
        glEnd();
    }
    if(0.5f >= range.start && 0.5f < range.end)
    {
        glTranslatef(0, 0, -0.5);
        glColor3f(1, 0, 0);
        glBegin(GL_QUADS);
        glVertex2d(-1.0, -1.0);
        glVertex2d( 1.0, -1.0);
        glVertex2d( 1.0,  1.0);
        glVertex2d(-1.0,  1.0);
        glEnd();
    }
}
